package com.tw.config;

import javax.sql.DataSource;

import org.jooq.DSLContext;
import org.jooq.impl.DSL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.alibaba.druid.pool.DruidDataSource;


@EnableTransactionManagement
public class DataSourceConfig {

	@Bean(name = "learnJooqTransactionManager")
	public PlatformTransactionManager learnJooqTransactionManager(
			@Autowired @Qualifier("learnJooqDataSource") DataSource dataSource) {
		return new DataSourceTransactionManager(dataSource);
	}

	@Bean(name = "learnJooq2TransactionManager")
	public PlatformTransactionManager learnJooq2TransactionManager(
			@Autowired @Qualifier("learnJooq2DataSource") DataSource dataSource) {
		return new DataSourceTransactionManager(dataSource);
	}

	@Bean(name = "learnJooqDataSource")
	@ConfigurationProperties(prefix = "spring.datasource")
	public DataSource learnJooqDataSource() {
		return new DruidDataSource();
	}

	@Bean(name = "learnJooq2DataSource")
	@ConfigurationProperties(prefix = "spring.datasource.db1")
	public DataSource learnJooq2DataSource() {
		return new DruidDataSource();
	}

}